package com.edu.bean;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/*
 * @Author:princess
 * @Date 2023/10/24 10 24 20:24
 *
 */

/*
    @Component 表示一个 一般的 bean对象
        默认的beanId 为类名 首字母小写后的名字
 */
@Component

public class User {
    private int userId;
    private String username;
    private String password;

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }

    public int getUserId() {
        return userId;
    }
    @Value("1")
    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }
    @Value("zhangsan")
    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    @Value("123456")
    public void setPassword(String password) {
        this.password = password;
    }

    public User() {
    }

    public User(int userId, String username, String password) {
        this.userId = userId;
        this.username = username;
        this.password = password;
    }

    @PostConstruct
    public void init(){
        System.out.println("执行了自定义初始化方法");
    }

    @PreDestroy
    public void myDestory(){
        System.out.println("执行了自定义销毁方法");
    }
}
